#include <bits/stdc++.h>
using namespace std;

typedef struct project{
	int k,b,x,increase;
	
	bool operator <(const project &other)const{
		return increase < other.increase;
	}
}project;

priority_queue<project> p;

int calculate(project &p){
	return p.k*(2*p.x+1)+p.b;
}


int main(){
	int n,m,ki,bi;
	int max = 0;
	project temp;
	cin >> n >> m;
	for(int i = 1;i <= m;i++){
		project q;
		cin >> ki >> bi;
		q.k = ki;
		q.b = bi;
		q.x = 0;
		q.increase = calculate(q);
		p.push(q);
	}
	for(int i = 1;i <= n&&!p.empty();i++){
		temp = p.top();
		p.pop();
		
		max += temp.increase;
		temp.x += 1;
		temp.increase = calculate(temp);
		if(temp.increase > 0){
			p.push(temp);	
		}

	}
	cout << max;
	return 0;
}
